package cn.ecut.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SendSms {
    public static int code = 0;
    public  static  int  sendMessage(String phoneNumber){
         code = RandomUtil.getRandNum();
        System.out.println(code);
        String accessKeyId="LTAI4GCrr97pVFArX82jQjDV";
        String accessSecret="TimBG5ChwOctJR0ncU7cEquEb4a41p";
        DefaultProfile profile =
                DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers",phoneNumber );
        request.putQueryParameter("SignName", "员工宿舍管理系统");
        request.putQueryParameter("TemplateCode", "SMS_206805056");
        request.putQueryParameter("TemplateParam", "{\"code\":"+code+"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return code;
    }
   /* public static int getCode(){
        System.out.println("验证码："+code);
        return code;
    }*/
}
